home *** CD-ROM | disk | FTP | other *** search
- /*
- All Shapes.c
-
- "All Shapes" creates, manipulates, and draws all of the QuickDraw™ GX primitive shapes. As each shape is created,
- it is added to "gthePage". This shape represents the contents of the window.
-
- This file contains the calls that an application needs to make for the "graphics shell" to work correctly.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c",
- "QDLibrary.c", "TransformLibrary.c".
-
- • This file prints the "best" in landscape mode.
-
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Changed fixed to Fixed.
- Updated the above note regarding the files needed to run, and copyright date.
-
- ©1992 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <events.h>
- #include <windows.h>
-
- #include "FontLibrary.h"
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include <GXErrors.h>
- #include "QDLibrary.h"
- #include "graphics shell.h"
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\pQuickDraw™ GX Primitive Shapes...";
- Rect gWindowQDRect = {50, 15, 475, 590};
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 85k, I had 11 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 85;
-
-
- //
- // Every time you create a new shape, it is added to "gthePage". We can then pass this shape to the GX Print Manager.
- // It will then print the entire page.
- //
- gxShape gthePage;
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
- //
- // In this function we gxInitialize the CommonColors Library, gObjectCount, gShapesInPicture, and gthePage.
- //
- void DoInitialization(gWindow)
- WindowPtr gWindow;
- {
- gxShape theLine, theRect, theCurve, thePath, theText, thePolygon, theBitmap;
- gxLine lineGeometricData = {ff(25), ff(25), ff(125), ff(125)};
- gxRectangle rectGeometricData = {ff(25), ff(25), ff(75), ff(75)};
- gxCurve curveGeometricData = {ff(25), ff(25), ff(275), ff(75), ff(125), ff(125)};
- long tripleBumpGeometricData[] = { 1, // number of contours
- 6, // number of points
- 0xff000000,
- 0, 0,
- ff(75), 0,
- ff(5), ff(50),
- ff(75), ff(100),
- 0, ff(100),
- ff(75), ff(50)};
-
- long starGeometricData[] = { 1, // number of contours
- 5 , // number of points
- ff(60), 0, ff(90), ff(90), ff(0), ff(30), ff(120), ff(30), ff(0), ff(90)}; // the points
- gxRectangle theTextBounds;
- gxColor textColor;
- Fixed x,y;
- short loop;
-
- //
- // We intialize the CommonColors Library. This will allow us to set the gxColor of a shape by calling the
- // SetShapeCommonColor function. We will need to call DisposeCommonColors in our DoDispose
- // function to clean up the world.
- //
- InitCommonColors();
-
- //
- // Create the "gthePage" shape. We set the unique items attribute to make sure that each item added to the
- // picture has a unique reference. If this attribute was not set, we would not see all six Q's rotated.
- // We would only see the last "Q" rotated; not all 6 pieces.
- //
- gthePage = GXNewShape(gxPictureType);
- GXSetShapeAttributes(gthePage, gxUniqueItemsShape);
-
- //
- // From this gxPoint on, this function adds all of the GX primitives to our picture - gthePage
- //
-
- //
- // Create a line
- //
- theLine = GXNewLine (&lineGeometricData);
- GXSetShapePen (theLine, ff(12));
- GXSetPictureParts(gthePage, 0, 0, 1, &theLine, nil, nil, nil);
- GXDisposeShape(theLine);
-
- //
- // Create a rectangle which is: red & is draw with it's frame.
- //
- theRect = GXNewRectangle(&rectGeometricData);
- SetShapeCommonColor (theRect, red);
- GXSetShapeFill (theRect, gxClosedFrameFill);
- GXMoveShapeTo (theRect, ff(150), ff(25));
-
- GXSetPictureParts(gthePage, 0, 0, 1, &theRect, nil, nil, nil);
- GXDisposeShape(theRect);
-
- //
- // Create a curve which has: a 3.25 pen thickness
- //
- theCurve = GXNewCurve(&curveGeometricData);
-
- // The fl marco converts floating gxPoint #'s to fixed gxPoint.
- GXSetShapePen(theCurve, fl(3.25));
- GXMoveShapeTo (theCurve, ff(210), ff(25));
-
- GXSetPictureParts(gthePage, 0, 0, 1, &theCurve, nil, nil, nil);
- GXDisposeShape(theCurve);
-
- //
- // Create a path which has: a 2 pen thickness, it's gxColor is green, and it's drawn with it's frame
- //
- thePath = GXNewPaths((gxPaths *) tripleBumpGeometricData);
- GXSetShapeFill (thePath, gxClosedFrameFill);
- GXSetShapePen(thePath, ff(2));
- SetShapeCommonColor (thePath, green);
-
- GXMoveShapeTo (thePath, ff(390), ff(25));
-
- GXSetPictureParts(gthePage, 0, 0, 1, &thePath, nil, nil, nil);
- GXDisposeShape(thePath);
-
- //
- // Create a character "GX" which is: colored in hsv space and it is rotated 15 degrees - six times via the left bottom corner.
- //
- theText = GXNewText(2,(unsigned char*)"GX", nil);
- SetShapeCommonFont(theText, timesFont);
- GXSetShapeTextSize(theText, ff(120));
- GXMoveShapeTo (theText, ff(15), ff(225));
-
- // Create an hsv gxColor space and set up the initial colors
- textColor.space = gxHSVSpace;
- textColor.profile = nil;
- textColor.element.hsv.hue = 0x7400;
- textColor.element.hsv.saturation = 0xFFFF;
- textColor.element.hsv.value = 0xFFFF;
-
- // Get the bounds of "theText" and determine the bottom left corner
- GXGetShapeBounds(theText, 0L, &theTextBounds);
- x = theTextBounds.left;
- y = theTextBounds.bottom;
-
- // Rotate "theText" 15 degrees - 6 times. Add each letter to the picture.
- for (loop = 0; loop < 6; loop++) {
- GXSetShapeColor(theText, &textColor);
- GXSetShapeAttributes(theText, gxMapTransformShape);
- GXRotateShape(theText, ff(15), x, y);
-
- GXSetPictureParts(gthePage, 0, 0, 1, &theText, nil, nil, nil);
-
- textColor.element.hsv.hue += 0x0940;
- }
- GXDisposeShape(theText);
-
- //
- // Create a polygon which has the following features: yellow, drawn with a pen = 3, and skew it in the vertical direction by 0.5
- //
- thePolygon = GXNewPolygons((gxPolygons *) starGeometricData);
- GXSetShapeFill(thePolygon, gxEvenOddFill);
- GXSetShapePen (thePolygon, ff(3));
- SetShapeCommonColor (thePolygon, yellow);
- GXMoveShapeTo (thePolygon, ff(240), ff(110));
- GXSkewShape(thePolygon, 0, fl(0.5), 0, 0);
-
- GXSetPictureParts(gthePage, 0, 0, 1, &thePolygon, nil, nil, nil);
- GXDisposeShape(thePolygon);
-
- //
- // Retrieve a bitmap from the resource fork and skew it in the horizontal direction by 2.
- //
- theBitmap = GetPixMapShape(128);
- GXValidateShape (theBitmap);
-
- GXSkewShape(theBitmap, ff(2), 0, 0, 0);
- GXMoveShapeTo (theBitmap, ff(290), ff(190));
-
- GXSetPictureParts(gthePage, 0, 0, 1, &theBitmap, nil, nil, nil);
- GXDisposeShape(theBitmap);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
- //
- // Draw the contents of "gthePage".
- //
- void DoDraw(gWindow)
- WindowPtr gWindow;
- {
- GXDrawShape (gthePage);
- }
-
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(gWindow)
- WindowPtr gWindow;
- {
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
- GXDisposeShape(gthePage);
- GXDisposeShape(gWindowBoundsShape);
- DisposeCommonColors();
- DisposeWindow(gWindow);
- }
-
-
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(gWindow)
- WindowPtr gWindow;
- {
- }
-